import {
  major_select,
  getJhmjListIndex,
  getQuizDetail_chat,
  getWendaList,
  getJhmjList,
  major_list,
  getLaizhanList
} from "@/assets/api/csjhApi";
import {
  getpcslideshow
} from "@/assets/api/indexApi";


export const state = () => ({

  entering: false, // 对方是否正在输入

  lunbo: [],
  majorList: [],
  jxwtList: [],

  QuizDetail: false,
  wendaList: null,

  problemList1x: [],
  problemList2x: [],
  zjwd_total: 0,
  problemList3x: [],


})

export const getters = {
  hotSearchList: (state) => state.hotSearchList,

  lunbo: (state) => state.lunbo,
  majorList: (state) => state.majorList,
  jxwtList: (state) => state.jxwtList,
}

export const mutations = {

  set_entering(state, data) {
    state.entering = data
  },
  set_Init(state, data) {
    state.lunbo = data.lunbo
    state.majorList = data.majorList
    state.jxwtList = data.jxwtList
  },
  set_DetailInit(state, data) {
    state.QuizDetail = data.QuizDetail
    state.wendaList = data.wendaList
  },

  set_ProblemInit(state, data) {
    if (data.tab == 'jxhd')
      state.problemList1x = data.data
    else if (data.tab == 'zjwd') {
      state.problemList2x = data.data.data
      state.zjwd_total = data.data.allcount
    } else if (data.tab == 'dnld') {
      state.problemList3x = data.data
    }
  }
}

export const actions = {
  // 获取用户信息
  async Init({
    commit,
    state
  }, params) {
    const res1 = await getpcslideshow({
      type: 10,
    })
    const res2 = await major_select({})
    const res3 = await getJhmjListIndex({
      limit: 20,
      page: 1,
      sort: 0,
    })
    commit('set_Init', {
      lunbo: res1.data,
      majorList: res2.data,
      jxwtList: res3.data,
    })
  },

  async DetailInit({
    commit,
    state
  }, params) {
    const res1 = await getQuizDetail_chat({
      quiz_id: params.id,
      status: 3
    })
    const res2 = await getWendaList({})
    commit('set_DetailInit', {
      QuizDetail: res1.data,
      wendaList: res2,
    })
  },

  async ProblemInit({
    commit,
    state
  }, params) {
    let data = null
    if (params.tab == 'jxhd') {
      data = await getJhmjList({
        limit: 20,
        page: params.page,
        sort: 2,
      })
    } else if (params.tab == 'zjwd') {
      data = await major_list({
        limit: 20,
        page: params.page,
      })
    } else if (params.tab == 'dnld') {
      data = await getLaizhanList({
        limit: 20,
        page: params.page,
      })
    }
    if (data && data.code == 1) {
      commit('set_ProblemInit', {
        data: data.data,
        tab: params.tab
      })
    }

  },

}
